package com.zhou.sharingjdbc.controller;

import com.alibaba.fastjson.JSONObject;
import com.zhou.sharingjdbc.dao.entity.Dm;
import com.zhou.sharingjdbc.service.IDmService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @author zhouyongjun
 * @date 2021/3/3019:13
 * @Description:
 */
@RestController
@RequestMapping("/dm")
public class DmController {
    @Autowired
    IDmService dmService;
    @GetMapping("get/{id}")
    public Dm getDm(@PathVariable("id") Integer id) {
        Dm dm = dmService.getDmById(id);
        return dm;
    }
    @GetMapping("list")
    public List<Dm> getDm() {
       return dmService.getAll();
    }
    @PostMapping("add")
    public boolean add(Dm dm) {
        return dmService.addDm(dm);
    }
    @DeleteMapping("delete/{id}")
    public boolean delete(@PathVariable("id") Integer id){
        return dmService.deleteDm(id);
    }
    @PostMapping("update/{id}")
    public JSONObject update(@PathVariable("id") Integer id,String name) {
        JSONObject jsonObject = new JSONObject();
        jsonObject.put("id",id);
        jsonObject.put("name",name);
        return jsonObject;
    }

}
